package com.yksj.healthtalk.ui.friend;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.FragmentManager;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.EditText;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.yksj.healthtalk.comm.BaseFragmentActivity;
import com.yksj.healthtalk.entity.CustomerInfoEntity;
import com.yksj.healthtalk.ui.R;
import com.yksj.healthtalk.utils.ToastUtil;

public class DoctorSearchMainActivity extends BaseFragmentActivity implements OnClickListener{
	
	
	private LinearLayout mSearchAddressLin;
	private LinearLayout mSearchFriendLin;
	private EditText mDuoMeiNum;
	private FrameLayout fragmentContent;
	private ImageView icon;
	private Intent intent;
	private FragmentManager f;
	private CustomerInfoEntity mCustomerInfoEntity;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.friend_search_main_layout);
		initWidget();
		initData();
	}
	
	private void initData() {
		titleLeftBtn.setText(R.string.back);
		titleRightBtn2.setVisibility(View.VISIBLE);
		titleRightBtn2.setText(R.string.sure);
		
		titleTextV.setText(R.string.search_doctor);
		intent = getIntent();
		if (intent.hasExtra("mCustomerInfoEntity")) {
			mCustomerInfoEntity =intent.getExtras().getParcelable("mCustomerInfoEntity");
		}else {
			mCustomerInfoEntity = new CustomerInfoEntity();
		}
	}

	private void initWidget() {
		initTitle();
		findViewById(R.id.split_0).setVisibility(View.GONE);
		mSearchFriendLin = (LinearLayout)findViewById(R.id.search_friend_lin);
		mSearchAddressLin = (LinearLayout)findViewById(R.id.search_address_lin);
		mDuoMeiNum = (EditText)findViewById(R.id.duomei_num_et);
		//设置监听
		titleLeftBtn.setOnClickListener(this);
		mSearchFriendLin.setOnClickListener(this);		
		titleRightBtn2.setOnClickListener(this);
		findViewById(R.id.search_zxing_lin).setOnClickListener(this);
		//初始化布局
		mSearchAddressLin.setVisibility(View.GONE);
	}

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		switch (v.getId()) {
		case R.id.search_zxing_lin:
			intent = new Intent();
			intent.setClass(getApplicationContext(), FriendSearchAboutZxingActivity.class);
			intent.putExtra("type","1");// 0-社交场  1-医生馆
			startActivity(intent);
			break;
		case R.id.search_friend_lin:
			Intent intent2 = new Intent();
			intent2.putExtra("mCustomerInfoEntity", mCustomerInfoEntity);
			intent2.setClass(this, FriendSearchAboutDoctorActivity.class);
			startActivityForResult(intent2, 0);
			break;
		case R.id.title_right2:
			//多美号没有
			String str = mDuoMeiNum.getText().toString();
			if (str.equals("")) {
				ToastUtil.showShort(this,"对不起多美号和昵称不能为空~");
				return;
			}
			
			Intent intent  = new Intent(getApplicationContext(),FriendSearchUI.class);
			intent.putExtra("duoMeiNum", mDuoMeiNum.getText().toString());
			startActivity(intent);
			break;
		case R.id.title_back:
			setResult(-1);
			finish();
			break;
		}
	}
	
	@Override
	protected void onActivityResult(int arg0, int arg1, Intent arg2) {
		if (arg2 !=null && arg2.hasExtra("mCustomerInfoEntity")) {
			intent.putExtra("mCustomerInfoEntity", arg2.getExtras().getParcelable("mCustomerInfoEntity"));
			setResult(0,intent);
			finish();
		}else {
			setResult(-1);
			finish();
		}
		super.onActivityResult(arg0, arg1, arg2);
	}


}
